Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formatNumber; filter log tickFormat function #2078

Merged
merged 4 commits into from
Jun 10, 2024

Conversation

mbostock
Copy link
Member

Fixes #2077. Also exposes Plot.formatNumber(locale).

@mbostock mbostock requested a review from Fil June 10, 2024 00:06
@mbostock mbostock enabled auto-merge (squash) June 10, 2024 00:06
@mbostock mbostock force-pushed the mbostock/log-format-function branch from 507264a to d9a98e9 Compare June 10, 2024 00:07
Copy link
Contributor

@Fil Fil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the feature — I hope we'll find a way to solve #384 too!

Two small comments/questions.

@@ -652,7 +652,7 @@ function inferTextChannel(scale, data, ticks, tickFormat, anchor) {
// possible, or the default ISO format (2014-01-26). TODO We need a better way
// to infer whether the ordinal scale is UTC or local time.
export function inferTickFormat(scale, data, ticks, tickFormat, anchor) {
return typeof tickFormat === "function"
return typeof tickFormat === "function" && !(scale.type === "log" && scale.tickFormat)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return typeof tickFormat === "function" && !(scale.type === "log" && scale.tickFormat)
return typeof tickFormat === "function" && scale.type !== "log"

Nit: I'm not sure about the case for the second part of the test. When scale.type is "log", the scale is an instance of d3.scaleLog() and it has a tickFormat method, which the user can't nullify.

Copy link
Member Author

@mbostock mbostock Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn’t do this because I didn’t want to assume that log scales necessarily implement scale.tickFormat. That is currently true, but if this assumption doesn’t hold in the future, this would break.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error may be mine, but this "invalid" message comes from the format in many European languages returning 2 000 which is not accepted in SVG.

Copy link
Member Author

@mbostock mbostock Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem comes from running beautify.html on the generated SVG, meaning that the SVG is assumed to be in HTML. We’ll have to find a way to disable that for tests.

Edit: Actually it’s from JSDOM’s outerHTML serialization.

@mbostock mbostock merged commit 27ec3b8 into main Jun 10, 2024
1 check passed
@mbostock mbostock deleted the mbostock/log-format-function branch June 10, 2024 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

For a log scale, the tickFormat function should only be considered for ticks that should be visible
2 participants